package com.future.dao;

import java.sql.Connection;
import java.util.List;

import com.future.model.po.InforRateModel;

public class InforRateDAO extends BaseDAO<InforRateModel> {

	public InforRateDAO() {

	}

	public InforRateDAO(Connection conn) {
		super(conn);
	}

	public boolean save(InforRateModel model) {
		String sql = "insert into infor_rate (userid , departmentid,rate) values (?,?,?)";
		return this.update(sql, model.getUserid(), model.getDepartmentId(), model.getRate());
	}

	public List<InforRateModel> findAll() {
		String sql = "select * from infor_rate";
		return this.searchAsBeanList(sql, InforRateModel.class);
	}

	public List<InforRateModel> findByUserId(Integer userId) {
		InforRateModel model = new InforRateModel();
		model.setUserid(userId);
		return this.findByUserId(model);
	}

	public List<InforRateModel> findByUserId(InforRateModel model) {
		String sql = "select * from infor_rate where userid = ?";
		return this.searchAsBeanList(sql, InforRateModel.class, model.getUserid());
	}

	public boolean modify(InforRateModel model) {
		String sql = "update infor_rate set departmentid = ? , rate = ? where userid = ?";
		return this.update(sql, model.getDepartmentId(), model.getRate(), model.getUserid());
	}
	public boolean update(InforRateModel model) {
		String sql = "update infor_rate set rate = ? where userid = ? and  departmentid=?";
		return this.update(sql, model.getRate(), model.getUserid(), model.getDepartmentId());
	}

	public boolean deleteByUserId(Integer userId) {
		InforRateModel model = new InforRateModel();
		model.setUserid(userId);
		return deleteByUserId(model);
	}

	public boolean deleteByUserId(InforRateModel model) {
		String sql = "delete from infor_rate where userid = ? ";
		return this.update(sql, model.getUserid());
	}

}
